<template>
  <div class="container">
    <div v-if="!showDetail">
      <!-- 搜索 -->
      <table>
        <tr>
          <th>
            <span>校区：</span>
            <el-button
              @click="openCampusList = true"
              type="text"
              style="width: 250px; text-align: left;"
            >
              <span v-if="campusSelect">{{campusSelect.name}}</span>
              <span v-else>未选择</span>
            </el-button>
          </th>
          <th>
            <span>功能区：</span>
            <el-button
              @click="openAreaList = true"
              type="text"
              style="width: 250px; text-align: left;"
            >
              <span v-if="areaSelect">{{areaSelect.name}}</span>
              <span v-else>未选择</span>
            </el-button>
          </th>
          <th></th>
        </tr>
        <tr>
          <th>
            <span>场地类型：</span>
            <el-button
              @click="openFieldTypeList = true"
              type="text"
              style="width: 250px; text-align: left;"
            >
              <span v-if="fieldTypeSelect">{{fieldTypeSelect.type_name}}</span>
              <span v-else>未选择</span>
            </el-button>
          </th>
          <th style="width: 400px;">
            <span>场地名称：</span>
            <el-button
              @click="openFieldList = true"
              type="text"
              style="width: 250px; text-align: left;"
            >
              <span v-if="fieldSelect">{{fieldSelect.name}}</span>
              <span v-else>未选择</span>
            </el-button>
          </th>
          <th style="width: 100px;">
            <el-button type="primary" icon="el-icon-search" @click="searchField">搜索</el-button>
          </th>
        </tr>
      </table>
      <!-- 场地类型筛选 -->
      <el-dialog title="选择场地类型" :visible.sync="openFieldTypeList">
        <el-input placeholder="请输入关键字" v-model="fieldTypeKeyword">
          <template slot="prepend">场地类型</template>
          <el-button slot="append" icon="el-icon-search" @click="getFieldTypeByKeyword"></el-button>
        </el-input>
        <br />
        <br />
        <el-radio-group v-model="fieldTypeSelect">
          <el-radio
            v-for="(fieldType, index) in fieldTypeList"
            :key="'fieldType'+index"
            :label="fieldType"
          >{{fieldType.type_name}}</el-radio>
        </el-radio-group>
        <div slot="footer" class="dialog-footer">
          <el-button @click="fieldTypeSelect = ''">清 空</el-button>
          <el-button type="primary" @click="openFieldTypeList = false">确 定</el-button>
        </div>
      </el-dialog>
      <!-- 场地筛选 -->
      <el-dialog title="选择场地" :visible.sync="openFieldList">
        <el-input placeholder="请输入关键字" v-model="fieldKeyword">
          <template slot="prepend">场地名称</template>
          <el-button slot="append" icon="el-icon-search" @click="getFieldByKeyword"></el-button>
        </el-input>
        <br />
        <br />
        <el-radio-group v-model="fieldSelect">
          <el-radio
            v-for="(field, index) in fieldList"
            :key="'field'+index"
            :label="field"
          >{{field.name}}</el-radio>
        </el-radio-group>
        <div slot="footer" class="dialog-footer">
          <el-button @click="fieldSelect = ''">清 空</el-button>
          <el-button type="primary" @click="openFieldList = false">确 定</el-button>
        </div>
      </el-dialog>
      <!-- 校区筛选 -->
      <el-dialog title="选择校区" :visible.sync="openCampusList">
        <el-input placeholder="请输入关键字" v-model="campusKeyword">
          <template slot="prepend">校区名</template>
          <el-button slot="append" icon="el-icon-search" @click="getCampusByKeyword"></el-button>
        </el-input>
        <br />
        <br />
        <el-radio-group v-model="campusSelect">
          <el-radio
            v-for="(campus, index) in campusList"
            :key="'campus' + index"
            :label="campus"
          >{{ campus.name }}</el-radio>
        </el-radio-group>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="campusSelect = ''">清 空</el-button>
          <el-button type="primary" @click="openCampusList = false">确 定</el-button>
        </div>
      </el-dialog>
      <!-- 功能区筛选 -->
      <el-dialog title="选择功能区" :visible.sync="openAreaList">
        <el-input placeholder="请输入关键字" v-model="areaKeyword">
          <template slot="prepend">功能区名</template>
          <el-button slot="append" icon="el-icon-search" @click="getAreaByKeyword"></el-button>
        </el-input>
        <br />
        <br />
        <el-radio-group v-model="areaSelect">
          <el-radio
            v-for="(area, index) in areaList"
            :key="'area' + index"
            :label="area"
          >{{ area.name }}</el-radio>
        </el-radio-group>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="areaSelect = ''">清 空</el-button>
          <el-button type="primary" @click="openAreaList = false">确 定</el-button>
        </div>
      </el-dialog>
      <hr />
      <!-- 场地列表 -->
      <el-table
        :data="fieldList.slice((currentPage-1)*pagesize,currentPage*pagesize)"
        stripe
        border
        @row-click="rowClick"
      >
        <el-table-column prop="campus.name" label="校区" />
        <el-table-column prop="area.name" label="功能区" />
        <el-table-column prop="name" label="名称" />
        <el-table-column prop="english_name" label="英文名称" />
        <el-table-column prop="fieldType.name" label="类型" />
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 20, 50]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableTotal"
        style="margin-left: 30%;"
      ></el-pagination>
    </div>
    <!-- 场地详情 -->
    <div v-else>
      <fieldDetails :fieldDetails="fieldDetails" @closeDetails="closeDetails" />
    </div>
  </div>
</template>
<script>
import fieldDetails from "@/views/education-collegeField/field/details";

export default {
  name: "field",
  data() {
    return {
      tableTotal: 0,
      currentPage: 1,
      pagesize: 10,
      search_fieldName: "", //场地名称关键词---输入的搜索条件
      showDetail: false, //场地详情显示
      fieldDetails: {}, //某一行场地的详情
      fieldList: [], //场地列表

      openCampusList: false, //校区筛选显示
      campusSelect: "", //校区选择
      campusList: [], //校区列表
      campusKeyword: "", //校区搜索关键词

      openAreaList: "", //功能区筛选显示
      areaSelect: "", //功能区选择
      areaList: [], //功能区列表
      areaKeyword: "", //功能区搜索关键词

      openFieldTypeList: false, //场地类型筛选对话框显示
      fieldTypeKeyword: "", //场地类型关键词
      fieldTypeSelect: "", //场地类型选择
      fieldTypeList: [], //场地类型列表

      openFieldList: false, //场地筛选对话框显示
      fieldKeyword: "", //场地筛选关键词
      fieldSelect: "", //场地的选择
    };
  },
  components: {
    fieldDetails,
  },
  created() {
    //获取场地列表
    this.getFieldList();
    //获取场地类型列表
    this.getFieldTypeList();
    //获取功能区列表
    this.getAreaList();
    //获取校区列表
    this.getCampusList();
  },
  methods: {
    //获取场地列表
    getFieldList() {
      this.fieldList = [
        {
          id: "01", //编号
          name: "第一教学楼", //名称
          english_name: "", //英文名称
          telephone: "", //电话号码
          discription: "", //描述
          campus: { id: "01", name: "主校区", discription: "" }, //校区
          area: { id: "01", name: "美术楼", discription: "" }, //功能区
          fieldType: { id: "01", name: "室内", discription: "" }, //场地类型
          by_who: { id: "01", name: "张三" }, //负责人
          create_time: "", //创建时间
        },
        {
          id: "02",
          name: "第二教学楼",
          english_name: "",
          telephone: "",
          discription: "",
          campus: { id: "02", name: "星湖校区", discription: "" }, //校区
          area: { id: "02", name: "第一教学楼", discription: "" },
          fieldType: { id: "02", name: "室内", discription: "" },
          by_who: { id: "02", name: "李四" }, //创建者
          create_time: "",
        },
        {
          id: "03",
          name: "第三教学楼",
          english_name: "",
          telephone: "",
          discription: "",
          campus: { id: "03", name: "主校区", discription: "" }, //校区
          area: { id: "03", name: "实验楼", discription: "" },
          fieldType: { id: "03", name: "室内", discription: "" },
          by_who: { id: "03", name: "王五" }, //创建者
          create_time: "",
        },
      ];
    },

    //获取场地类型列表
    getFieldTypeList() {
      this.fieldTypeList = [
        {
          id: "01",
          type_name: "教学楼",
          english_name: "",
          discription: "",
          create_time: "",
        },
        {
          id: "02",
          type_name: "实验楼",
          english_name: "",
          discription: "",
          create_time: "",
        },
        {
          id: "03",
          type_name: "美术楼",
          english_name: "",
          discription: "",
          create_time: "",
        },
      ];
    },

    //获取功能区列表
    getAreaList() {
      this.areaList = [
        { id: "1", name: "第一教学楼" },
        { id: "2", name: "第二教学楼" },
        { id: "3", name: "第三教学楼" },
        { id: "4", name: "美术大楼" },
        { id: "5", name: "中巴科技园" },
      ];
    },

    //获取校区列表
    getCampusList() {
      this.campusList = [
        { id: "1", name: "主校区" },
        { id: "2", name: "星湖校区" },
      ];
    },

    //点击某一行，显示场地详情
    rowClick(val) {
      this.fieldDetails = val;
      this.showDetail = true;
    },

    //关闭详情页
    closeDetails(val) {
      this.showDetail = val;
    },

    //条件搜索
    searchField() {},

    //根据关键词搜索场地类型
    getFieldTypeByKeyword() {},

    //根据关键词搜索场地
    getFieldByKeyword() {},

    //根据关键词搜索校区
    getCampusByKeyword() {},

    //根据关键词搜索功能区
    getAreaByKeyword() {},

    // 换页
    handleSizeChange: function (size) {
      this.pagesize = size;
    },
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage;
    },
  },
};
</script>
<style scoped>
.container {
  width: 80%;
  max-width: 100%;
  margin: 20px auto;
}
span {
  font-weight: 500;
}
th {
  text-align: left;
}
</style>
